package org.dromara.pay.domain.request;

import io.swagger.v3.oas.annotations.Hidden;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.dromara.pay.domain.TopUp;
import org.dromara.pay.constant.PayWaysConstant;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 支付参数
 *
 * @author zlj
 * @since 2023/7/28
 */
@Data
public class PayParam implements Serializable {
    public static final long serialVersionUID = 1L;

    /**
     * 订单号 对应 topUpId
     */
    @Hidden
    private String outTradeNo;
    /**
     * 支付方式 {@link PayWaysConstant}
     */
    @NotBlank(message = "请选择支付方式")
    private String payWay;
    /**
     * 订单总金额，单位为元
     */
    @DecimalMin(value = "0.01", message = "金额非法1")
    @NotNull(message = "金额非法2")
    @Digits(integer = 10, fraction = 2, message = "金额非法3")
    private BigDecimal amount;
    /**
     * 商品描述
     */
    private String desc;
    /**
     * 附加参数,在查询API和支付通知中原样返回，可作为自定义参数使用，实际情况下只有支付完成状态才会返回该字段。
     */
    private String attach;
    /**
     * 业务订单类型
     */
    private String orderType;

    public TopUp toTopUp() {
        TopUp topUp = new TopUp();
        topUp.setTotal(this.amount);
        topUp.setPayWay(this.payWay);
        topUp.setOrderJson(this.attach);
        topUp.setOrderType(this.orderType);
        return topUp;
    }
}
